using System.Collections;
using System.Collections.Generic;
using Datas;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.EventSystems;

public class Goods : MonoBehaviour,IPointerClickHandler
{
    // Start is called before the first frame update
    public Text goodsName;
    public Text money;
    private int _money;
    public Image goodsImage;

    private int _goodsID;

    public GameObject prompBox;

    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        
    }

    public void GetDb(string name,string Money,Sprite img,int goodsid)
    {
        goodsName.text = name;
        money.text = Money;
        goodsImage.sprite = img;
        _goodsID = goodsid;
    }
    
    //点击商品，把商品添加进背包
    public void OnPointerClick(PointerEventData eventData)
    {
       var playMoney=PlayerData.GetMoney();
        if (playMoney>int.Parse(money.text))
        {
            PlayerData.ChangeMoney(-int.Parse(money.text));
            PlayerData.AddCardId(_goodsID);


            Shop.SetShopState = (int)Shop.ShopState.ShopSuccess;
            
           
            Destroy();
           
        }
        else
        {
            
            Shop.SetShopState = (int)Shop.ShopState.Shopfail;
          
        }

    }

    private void Destroy()
    {
        Destroy(transform.gameObject);
    }
    
}
